<template>
  <div class="home-page">
    <!-- 欢迎横幅 -->
    <div class="welcome-banner">
      <div class="banner-content">
        <h1 class="banner-title">
          <el-icon class="banner-icon"><School /></el-icon>
          欢迎使用 AI 辅助学生信息管理系统
        </h1>
        <p class="banner-subtitle">智能化的学生数据管理、成绩分析与教学辅助平台</p>
      </div>
    </div>

    <!-- 统计卡片 -->
    <el-row :gutter="24" class="stats-row">
      <el-col :xs="24" :sm="12" :md="12" :lg="12">
        <div class="stat-card stat-card-students">
          <div class="stat-card-inner">
            <div class="stat-icon-wrapper">
              <div class="stat-icon">
                <el-icon :size="48"><User /></el-icon>
              </div>
            </div>
            <div class="stat-info">
              <div class="stat-label">学生总数</div>
              <div class="stat-value">{{ statistics.totalStudents }}</div>
              <div class="stat-desc">已录入系统</div>
            </div>
          </div>
          <div class="stat-card-bg"></div>
        </div>
      </el-col>

      <el-col :xs="24" :sm="12" :md="12" :lg="12">
        <div class="stat-card stat-card-classes">
          <div class="stat-card-inner">
            <div class="stat-icon-wrapper">
              <div class="stat-icon">
                <el-icon :size="48"><School /></el-icon>
              </div>
            </div>
            <div class="stat-info">
              <div class="stat-label">班级数量</div>
              <div class="stat-value">{{ statistics.totalClasses }}</div>
              <div class="stat-desc">正在管理中</div>
            </div>
          </div>
          <div class="stat-card-bg"></div>
        </div>
      </el-col>
    </el-row>

    <!-- 功能快捷入口 -->
    <div class="section-title">
      <el-icon class="section-icon"><Grid /></el-icon>
      <span>功能导航</span>
    </div>
    <el-row :gutter="24" class="features-row">
      <el-col :xs="24" :sm="12" :md="8" :lg="6" v-for="feature in features" :key="feature.path">
        <div class="feature-card" @click="$router.push(feature.path)">
          <div class="feature-icon-wrapper">
            <div :class="['feature-icon', feature.iconClass]">
              <el-icon :size="56"><component :is="feature.icon" /></el-icon>
            </div>
          </div>
          <h3 class="feature-title">{{ feature.title }}</h3>
          <p class="feature-desc">{{ feature.desc }}</p>
          <div class="feature-action">
            <span>{{ feature.action }}</span>
            <el-icon><ArrowRight /></el-icon>
          </div>
        </div>
      </el-col>
    </el-row>

    <!-- 快速开始 -->
    <div class="section-title">
      <el-icon class="section-icon"><Guide /></el-icon>
      <span>快速开始</span>
    </div>
    <div class="quick-start-card">
      <el-steps :active="1" align-center class="custom-steps">
        <el-step title="录入学生信息" description="添加学生基本信息和成绩">
          <template #icon>
            <div class="step-icon step-icon-1">
              <el-icon><EditPen /></el-icon>
            </div>
          </template>
        </el-step>
        <el-step title="查询和筛选" description="按条件查找和筛选学生">
          <template #icon>
            <div class="step-icon step-icon-2">
              <el-icon><Search /></el-icon>
            </div>
          </template>
        </el-step>
        <el-step title="AI分析报告" description="生成智能成绩分析报告">
          <template #icon>
            <div class="step-icon step-icon-3">
              <el-icon><MagicStick /></el-icon>
            </div>
          </template>
        </el-step>
      </el-steps>

      <div class="quick-action">
        <el-button type="primary" size="large" class="action-button" @click="$router.push('/students/add')">
          <el-icon><Plus /></el-icon>
          立即添加学生
        </el-button>
        <el-button size="large" class="action-button-secondary" @click="$router.push('/students')">
          <el-icon><View /></el-icon>
          查看学生列表
        </el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { getStudents } from '@/api/student'
import { User, School, Filter, DataAnalysis, PieChart } from '@element-plus/icons-vue'

const router = useRouter()

const statistics = ref({
  totalStudents: 0,
  totalClasses: 0
})

const features = [
  {
    title: '学生管理',
    desc: '学生信息的录入、查询、修改和删除',
    icon: User,
    iconClass: 'icon-blue',
    path: '/students',
    action: '进入管理'
  },
  {
    title: '班级管理',
    desc: '班级信息管理和班级成绩统计分析',
    icon: School,
    iconClass: 'icon-red',
    path: '/classes',
    action: '进入管理'
  },
  {
    title: '智能筛选',
    desc: '按班级、成绩等条件快速筛选学生',
    icon: Filter,
    iconClass: 'icon-green',
    path: '/students',
    action: '开始筛选'
  },
  {
    title: 'AI成绩分析',
    desc: 'AI辅助生成成绩分析报告和改进建议',
    icon: DataAnalysis,
    iconClass: 'icon-orange',
    path: '/analysis',
    action: '查看分析'
  },
  {
    title: '分类统计',
    desc: '按班级、课程等维度进行成绩分类分析',
    icon: PieChart,
    iconClass: 'icon-purple',
    path: '/classification',
    action: '查看统计'
  }
]

// 加载统计数据
const loadStatistics = async () => {
  try {
    // 获取学生总数和班级数
    const studentsRes = await getStudents({ page: 1, limit: 1 })
    statistics.value.totalStudents = studentsRes.pagination.total

    // 通过API获取班级数量
    const classesResponse = await fetch('/api/students/filter/classes')
    const classesData = await classesResponse.json()
    if (classesData.success) {
      statistics.value.totalClasses = classesData.data.length
    }
  } catch (error) {
    console.error('加载统计数据失败:', error)
  }
}

onMounted(() => {
  loadStatistics()
})
</script>

<style scoped>
/* 页面容器 */
.home-page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0;
  animation: fadeIn 0.6s ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 欢迎横幅 */
.welcome-banner {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 16px;
  padding: 48px 40px;
  margin-bottom: 32px;
  box-shadow: 0 8px 32px rgba(102, 126, 234, 0.3);
  position: relative;
  overflow: hidden;
}

.welcome-banner::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -10%;
  width: 400px;
  height: 400px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  animation: float 6s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(10deg); }
}

.banner-content {
  position: relative;
  z-index: 1;
}

.banner-title {
  color: white;
  font-size: 32px;
  font-weight: 700;
  margin: 0 0 12px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.banner-icon {
  font-size: 40px;
}

.banner-subtitle {
  color: rgba(255, 255, 255, 0.9);
  font-size: 16px;
  margin: 0;
}

/* 统计卡片 */
.stats-row {
  margin-bottom: 32px;
}

.stat-card {
  background: white;
  border-radius: 16px;
  padding: 32px;
  height: 180px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  margin-bottom: 24px;
}

.stat-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
}

.stat-card-inner {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 100%;
}

.stat-icon-wrapper {
  flex-shrink: 0;
}

.stat-icon {
  width: 100px;
  height: 100px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  transition: all 0.3s;
}

.stat-card:hover .stat-icon {
  transform: scale(1.1) rotate(5deg);
}

.stat-card-students .stat-icon {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.stat-card-classes .stat-icon {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.stat-info {
  flex: 1;
}

.stat-label {
  color: #909399;
  font-size: 16px;
  margin-bottom: 8px;
  font-weight: 500;
}

.stat-value {
  font-size: 48px;
  font-weight: 700;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
  margin-bottom: 4px;
}

.stat-card-classes .stat-value {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-desc {
  color: #C0C4CC;
  font-size: 14px;
}

.stat-card-bg {
  position: absolute;
  bottom: -20px;
  right: -20px;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  opacity: 0.1;
  transition: all 0.3s;
}

.stat-card-students .stat-card-bg {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.stat-card-classes .stat-card-bg {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.stat-card:hover .stat-card-bg {
  transform: scale(1.2);
  opacity: 0.15;
}

/* 分组标题 */
.section-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 24px;
  font-weight: 700;
  color: #303133;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 3px solid #f0f0f0;
}

.section-icon {
  font-size: 28px;
  color: #667eea;
}

/* 功能卡片 */
.features-row {
  margin-bottom: 32px;
}

.feature-card {
  background: white;
  border-radius: 16px;
  padding: 32px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  height: 100%;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}

.feature-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  transform: scaleX(0);
  transition: transform 0.4s;
}

.feature-card:hover::before {
  transform: scaleX(1);
}

.feature-card:hover {
  transform: translateY(-12px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.15);
}

.feature-icon-wrapper {
  margin-bottom: 20px;
}

.feature-icon {
  width: 100px;
  height: 100px;
  margin: 0 auto;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: all 0.4s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.feature-card:hover .feature-icon {
  transform: scale(1.15) rotate(-5deg);
}

.icon-blue {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.icon-red {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.icon-green {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.icon-orange {
  background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}

.icon-purple {
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
}

.feature-title {
  font-size: 20px;
  font-weight: 700;
  color: #303133;
  margin: 0 0 12px 0;
}

.feature-desc {
  color: #909399;
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 20px 0;
  flex: 1;
}

.feature-action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #667eea;
  font-size: 15px;
  font-weight: 600;
  transition: all 0.3s;
}

.feature-card:hover .feature-action {
  gap: 12px;
  color: #764ba2;
}

/* 快速开始 */
.quick-start-card {
  background: white;
  border-radius: 16px;
  padding: 40px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  margin-bottom: 32px;
}

.custom-steps {
  margin-bottom: 40px;
}

.step-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 24px;
}

.step-icon-1 {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.step-icon-2 {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.step-icon-3 {
  background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}

.quick-action {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.action-button,
.action-button-secondary {
  padding: 14px 32px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 12px;
  transition: all 0.3s;
}

.action-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(102, 126, 234, 0.4);
}

.action-button-secondary {
  background: white;
  border: 2px solid #667eea;
  color: #667eea;
}

.action-button-secondary:hover {
  background: #f5f7fa;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(102, 126, 234, 0.2);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .welcome-banner {
    padding: 32px 24px;
  }
  
  .banner-title {
    font-size: 24px;
  }
  
  .banner-subtitle {
    font-size: 14px;
  }
  
  .stat-card {
    height: auto;
    padding: 24px;
  }
  
  .stat-card-inner {
    flex-direction: column;
    text-align: center;
  }
  
  .stat-icon {
    width: 80px;
    height: 80px;
  }
  
  .stat-value {
    font-size: 36px;
  }
  
  .section-title {
    font-size: 20px;
  }
  
  .feature-card {
    min-height: auto;
  }
  
  .quick-start-card {
    padding: 24px;
  }
}
</style>
